//
//  MCMallStatisticsChooseObjectView.swift
//  StoreManage
//
//  Created by MC on 2018/8/30.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

typealias MCMallStatisticsChooseObjectViewClosure = (MCClerkManageModel) -> Void

class MCMallStatisticsChooseObjectView: UIView {

    
    var closure : MCMallStatisticsChooseObjectViewClosure?
    
        
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        self.layer.cornerRadius = 5
        self.layer.masksToBounds = true
        self.layer.borderWidth = 2
        self.layer.borderColor = UIColor.MCGray_light.cgColor
        
        self.addSubview(tableView)
        tableView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(self)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var tableView: MCTableView = {
        let tableView = MCTableView.init(frame: CGRect.zero, style: UITableViewStyle.plain)
        tableView.delegate = self
        tableView.dataSource = self
        return tableView
    }()
    
    lazy var dataArrayM: NSMutableArray = {
        let arrayM = NSMutableArray()
        return arrayM
    }()

    
}


extension MCMallStatisticsChooseObjectView : UITableViewDelegate,UITableViewDataSource {
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return dataArrayM.count
    }

    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        
        let model = self.dataArrayM[indexPath.row] as! MCClerkManageModel
        
        
        let cell = UITableViewCell.init(style: UITableViewCellStyle.value1, reuseIdentifier: "cell")
        
        cell.textLabel?.text = model.nickName
        cell.textLabel?.font = MCFont(14)

        
        let levelTuples = MCLevelConversion(level: model.level)
        cell.detailTextLabel?.text = levelTuples.levelName
        cell.detailTextLabel?.font = MCFont(12)

        cell.selectionStyle = UITableViewCellSelectionStyle.none
        cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
        let lineView = UIView()
        lineView.backgroundColor = UIColor.MCGray_light
        cell.contentView.addSubview(lineView)
        lineView.snp.remakeConstraints { (make) ->Void in
            make.left.right.bottom.equalTo(cell.contentView)
            make.height.equalTo(1)
        }
        
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.removeFromSuperview()
        
        let model = self.dataArrayM[indexPath.row] as! MCClerkManageModel
        closure?(model)
    }
}

